from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _

from media.models import File
from .project import Project

from .lib import ProjectSubMixin

class Examination(ProjectSubMixin, models.Model):
    project = models.ForeignKey(
        verbose_name=_("项目"),
        to=Project,
        on_delete=models.CASCADE,
    )
    investigation_time = models.DateField(
        verbose_name=_('检查时间'), 
        null=True, 
        blank=True, 
        default=None
    )
    unit_personnel = models.TextField(
        verbose_name=_('检查单位及人员'), 
        default='', 
        blank=True, 
        help_text=_('可用逗号隔开')
    )
    problem_rectify = models.TextField(
        verbose_name=_('问题及整改'), 
        default='', 
        blank=True, 
       help_text=_('可用逗号隔开')
    )

    class Meta:
        default_permissions = []
        db_table = 'project_examination'
        verbose_name = _('现场检查')
        verbose_name_plural = verbose_name

    @classmethod
    def get_link(cls, project_id, id):
        return reverse("project:examination/detail", kwargs={'project_pk': project_id, 'pk': id})

